package com.mljr.example.ui.home.tab1;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;

import com.ctakit.sdk.view.ViewInjector;
import com.ctakit.sdk.view.annotation.ViewInject;
import com.mljr.example.R;
import com.mljr.example.adapter.tab1.HeaderChannelAdapter;
import com.mljr.example.bean.tab1.ChannelIcon;

import java.util.List;


/**
 * Created by andyhome on 16/4/20.
 */
public class HeaderChannelView  {

    @ViewInject(R.id.gv_channel)
    FixedGridView gvChannel;

    protected Activity mContext;
    protected LayoutInflater mInflate;
    protected List<ChannelIcon> mEntity;

    public HeaderChannelView(Activity context) {
        this.mContext = context;
        mInflate = LayoutInflater.from(context);
    }

    public boolean fillView(List<ChannelIcon> t, List<View> views ) {
        if (t == null) {
            return false;
        }
        if ((t instanceof List) && ((List) t).size() == 0) {
            return false;
        }
        this.mEntity = t;
        getView(t,  views );
        return true;
    }

    protected void getView(List<ChannelIcon> list, List<View> views ) {
        View view = mInflate.inflate(R.layout.header_channel_layout, null, false);
        ViewInjector.inject(this, view);
        dealWithTheView(list);
        views.add(view);
    }

    private void dealWithTheView(List<ChannelIcon> list) {

/*      int size = list.size();
        if (size <= 4) {
            gvChannel.setNumColumns(size);
        } else if (size == 6) {
            gvChannel.setNumColumns(3);
        } else if (size == 8) {
            gvChannel.setNumColumns(4);
        } else {
            gvChannel.setNumColumns(4);
        }*/

        gvChannel.setNumColumns(4);
        HeaderChannelAdapter adapter = new HeaderChannelAdapter(mContext, list);
        gvChannel.setAdapter(adapter);
    }

}
